Imports System.Collections.Specialized

''' -----------------------------------------------------------------------------
''' Project	 : Common
''' Class	 : SkippableMessage
''' 
''' -----------------------------------------------------------------------------
''' <summary>
''' A class for SkippableMessageing operations that allows the user to dispatch it once and 
''' for all, agreeing to always SkippableMessage an operation from then on.
''' </summary>
''' <remarks>
''' </remarks>
''' <history>
''' 	[yvdh]	20/10/2004	Created
''' </history>
''' <exclude/>
''' -----------------------------------------------------------------------------
Public Class SkippableMessage
  Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

  End Sub

  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (components Is Nothing) Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(disposing)
  End Sub

  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer

  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.  
  'Do not modify it using the code editor.
  Friend WithEvents btnCancel As System.Windows.Forms.Button
  Friend WithEvents btnOk As System.Windows.Forms.Button
  Friend WithEvents chkDoNotShowAgain As System.Windows.Forms.CheckBox
  Friend WithEvents picQuestionMark As System.Windows.Forms.PictureBox
  Friend WithEvents txtMessage As System.Windows.Forms.TextBox
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(SkippableMessage))
    Me.btnCancel = New System.Windows.Forms.Button
    Me.btnOk = New System.Windows.Forms.Button
    Me.chkDoNotShowAgain = New System.Windows.Forms.CheckBox
    Me.picQuestionMark = New System.Windows.Forms.PictureBox
    Me.txtMessage = New System.Windows.Forms.TextBox
    CType(Me.picQuestionMark, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'btnCancel
    '
    Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
    Me.btnCancel.Location = New System.Drawing.Point(204, 79)
    Me.btnCancel.Name = "btnCancel"
    Me.btnCancel.Size = New System.Drawing.Size(64, 22)
    Me.btnCancel.TabIndex = 46
    Me.btnCancel.Text = "Cancel"
    '
    'btnOk
    '
    Me.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK
    Me.btnOk.Location = New System.Drawing.Point(116, 79)
    Me.btnOk.Name = "btnOk"
    Me.btnOk.Size = New System.Drawing.Size(64, 22)
    Me.btnOk.TabIndex = 45
    Me.btnOk.Text = "Ok"
    '
    'chkDoNotShowAgain
    '
    Me.chkDoNotShowAgain.FlatStyle = System.Windows.Forms.FlatStyle.Flat
    Me.chkDoNotShowAgain.Location = New System.Drawing.Point(8, 53)
    Me.chkDoNotShowAgain.Name = "chkDoNotShowAgain"
    Me.chkDoNotShowAgain.Size = New System.Drawing.Size(368, 25)
    Me.chkDoNotShowAgain.TabIndex = 47
    Me.chkDoNotShowAgain.Text = "Do not show this message again."
    '
    'picQuestionMark
    '
    Me.picQuestionMark.Image = CType(resources.GetObject("picQuestionMark.Image"), System.Drawing.Image)
    Me.picQuestionMark.Location = New System.Drawing.Point(8, 8)
    Me.picQuestionMark.Name = "picQuestionMark"
    Me.picQuestionMark.Size = New System.Drawing.Size(32, 32)
    Me.picQuestionMark.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
    Me.picQuestionMark.TabIndex = 49
    Me.picQuestionMark.TabStop = False
    '
    'txtMessage
    '
    Me.txtMessage.AcceptsReturn = True
    Me.txtMessage.BorderStyle = System.Windows.Forms.BorderStyle.None
    Me.txtMessage.Location = New System.Drawing.Point(48, 8)
    Me.txtMessage.Multiline = True
    Me.txtMessage.Name = "txtMessage"
    Me.txtMessage.ReadOnly = True
    Me.txtMessage.Size = New System.Drawing.Size(328, 40)
    Me.txtMessage.TabIndex = 50
    '
    'SkippableMessage
    '
    Me.AcceptButton = Me.btnOk
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.CancelButton = Me.btnCancel
    Me.ClientSize = New System.Drawing.Size(384, 109)
    Me.ControlBox = False
    Me.Controls.Add(Me.txtMessage)
    Me.Controls.Add(Me.picQuestionMark)
    Me.Controls.Add(Me.chkDoNotShowAgain)
    Me.Controls.Add(Me.btnCancel)
    Me.Controls.Add(Me.btnOk)
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
    Me.Name = "SkippableMessage"
    Me.ShowInTaskbar = False
    Me.Text = "Confirm"
    Me.TopMost = True
    CType(Me.picQuestionMark, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)
    Me.PerformLayout()

  End Sub

#End Region

  Private Shared oSkippableMessageClasses As New NameValueCollection

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' The only method of this class: show a SkippableMessageation dialog and keep track of
  ''' whether it has to be shown again in the future.
  ''' </summary>
  ''' <param name="oOwner">The parent form</param>
  ''' <param name="strClass">The class of the SkippableMessageation. This is used to identify the SkippableMessageation dialog and to keep track of whether it has to be shown again in the future</param>
  ''' <param name="strTitle">The dialog title</param>
  ''' <param name="strMessage">The dialog message</param>
  ''' <param name="bAllowCancel">Whether to allow skiiping this dialog in the future</param>
  ''' <param name="bAllowSkip">Whether to store user preference that allows skipping of this dialog in the future</param>
  ''' <returns>The dialog button that was pressed</returns>
  ''' <remarks>
  ''' </remarks>
  ''' <history>
  ''' 	[yvdh]	20/10/2004	Created
  ''' </history>
  ''' -----------------------------------------------------------------------------
  Public Overloads Shared Function Show(ByVal oOwner As System.Windows.Forms.Form, _
                                        ByVal strClass As String, _
                                        ByVal strTitle As String, _
                                        ByVal strMessage As String, _
                                        ByVal bAllowCancel As Boolean, _
                                        ByVal bAllowSkip As Boolean) As System.Windows.Forms.DialogResult
    Return Show(oOwner, strClass, strTitle, strMessage, False, bAllowCancel, bAllowSkip)
  End Function
  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' The only method of this class: show a SkippableMessageation dialog and keep track of
  ''' whether it has to be shown again in the future.
  ''' </summary>
  ''' <param name="oOwner">The parent form</param>
  ''' <param name="strClass">The class of the SkippableMessageation. This is used to identify the SkippableMessageation dialog and to keep track of whether it has to be shown again in the future</param>
  ''' <param name="strTitle">The dialog title</param>
  ''' <param name="strMessage">The dialog message</param>
  ''' <param name="bYesNo">Default we have Ok and Cancel buttons, use this to have Yes and No buttons instead</param>
  ''' <param name="bAllowCancel">Whether to allow skiiping this dialog in the future</param>
  ''' <param name="bAllowSkip">Whether to store user preference that allows skipping of this dialog in the future</param>
  ''' <returns>The dialog button that was pressed</returns>
  ''' <remarks>
  ''' </remarks>
  ''' <history>
  ''' 	[yvdh]	20/10/2004	Created
  ''' </history>
  ''' -----------------------------------------------------------------------------
  Public Overloads Shared Function Show(ByVal oOwner As System.Windows.Forms.Form, _
                                        ByVal strClass As String, _
                                        ByVal strTitle As String, _
                                        ByVal strMessage As String, _
                                        ByVal bYesNo As Boolean, _
                                        ByVal bAllowCancel As Boolean, _
                                        ByVal bAllowSkip As Boolean) As System.Windows.Forms.DialogResult


    If bAllowSkip And Not oSkippableMessageClasses.Get(strClass) Is Nothing Then
      'User has indicated he does not want to be prompted again
      Return CType(oSkippableMessageClasses.Item(strClass), System.Windows.Forms.DialogResult)
    Else
      Dim oSkippableMessage As New SkippableMessage

      oSkippableMessage.Hide()
      oSkippableMessage.Text = strTitle
      oSkippableMessage.txtMessage.Text = strMessage
      oSkippableMessage.chkDoNotShowAgain.Visible = bAllowSkip

      oSkippableMessage.SuspendLayout()
      oSkippableMessage.ClientSize = New System.Drawing.Size(oSkippableMessage.txtMessage.Width + oSkippableMessage.picQuestionMark.Width + 20, _
                    oSkippableMessage.txtMessage.Height + oSkippableMessage.chkDoNotShowAgain.Height + oSkippableMessage.btnOk.Height + 35)

      oSkippableMessage.chkDoNotShowAgain.Top = oSkippableMessage.txtMessage.Top + oSkippableMessage.txtMessage.Height + 10

      If Not bAllowCancel Then
        oSkippableMessage.btnCancel.Visible = False
        oSkippableMessage.btnOk.Top = oSkippableMessage.chkDoNotShowAgain.Top + oSkippableMessage.chkDoNotShowAgain.Height + 10
        oSkippableMessage.btnOk.Left = (oSkippableMessage.ClientSize.Width - oSkippableMessage.btnOk.Width) \ 2
      Else
        oSkippableMessage.btnOk.Top = oSkippableMessage.chkDoNotShowAgain.Top + oSkippableMessage.chkDoNotShowAgain.Height + 10
        oSkippableMessage.btnOk.Left = oSkippableMessage.ClientSize.Width \ 2 - oSkippableMessage.btnOk.Width - 10
        oSkippableMessage.btnCancel.Top = oSkippableMessage.chkDoNotShowAgain.Top + oSkippableMessage.chkDoNotShowAgain.Height + 10
        oSkippableMessage.btnCancel.Left = oSkippableMessage.ClientSize.Width \ 2 + 10
      End If

      If bYesNo Then
        oSkippableMessage.btnCancel.Text = "No"
        oSkippableMessage.btnCancel.DialogResult = Windows.Forms.DialogResult.No
        oSkippableMessage.btnOk.Text = "Yes"
        oSkippableMessage.btnOk.DialogResult = Windows.Forms.DialogResult.Yes
      End If

      oSkippableMessage.ResumeLayout()

      Dim oResult As System.Windows.Forms.DialogResult = oSkippableMessage.ShowDialog(oOwner)

      'Add class to Collection if required 
      If bAllowSkip And oSkippableMessage.chkDoNotShowAgain.Checked = True Then
        oSkippableMessageClasses.Add(strClass, CStr(CInt(oResult)))
      End If

      Return oResult
    End If
  End Function
End Class
